﻿namespace EFS.RC.SupervisorCentral.Controls.Conversations.Surveys
{
	/// <summary>
	/// Interaction logic for List.xaml
	/// </summary>
	public partial class List : EFS.RC.SupervisorCentral.Controls.Control
	{
		#region Locals
		/// lastSurveyClikedID
		private System.Object lastSurveyClikedID = null;
		#endregion

		#region Constructors
		/// Implicit
		public List()
		{
			InitializeComponent();
		}
		#endregion

		#region LoadData
		/// LoadData
		private void LoadData()
		{
			// Load surveys
			LoadSurveys();
		}

		/// Loads
		private void LoadSurveys()
		{
			try
			{
				// bind/fill form
				listViewSurveys.ItemsSource = EFS.RC.CC.CH.Tables.Surveys.GetAll(null, null, EFS.RC.CC.CH.Entities.Surveys.SurveyInfo.eReviewType.Agent);
			}
			catch (System.Exception ex)
			{
				ShowErrorMessage("Failed to retrieve data.", ex);
			}
		}
		#endregion

		#region Events
		/// Loaded
		private void Control_Loaded(object sender, System.Windows.RoutedEventArgs e)
		{
			//load data
			LoadData();
		}
		
		private void hyperlinkViewSurveyReport_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// get hyper link
			System.Windows.Documents.Hyperlink hyperLink = (System.Windows.Documents.Hyperlink)sender;

			// set
			lastSurveyClikedID = hyperLink.CommandParameter;

			// get url
			System.String navigateUri =
				EFS.RC.SupervisorCentral.Common.Main.GetReportViewURL(
					"Survey",
					new System.String[] { "surveyID" },
					new System.String[] { hyperLink.CommandParameter.ToString() });

			// start
			System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("iexplore", navigateUri));
			e.Handled = true; 
		}

		private void hyperlinkViewSurveyAgentReport_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			// get source
			System.Windows.Documents.Hyperlink hyperLink = (System.Windows.Documents.Hyperlink)sender;

			// set
			lastSurveyClikedID = hyperLink.CommandParameter;

			// create host
			EFS.Common.UI.Controls.ModalDialogHost agentSearchADHost = new EFS.Common.UI.Controls.ModalDialogHost();

			// create list
			EFS.RC.SupervisorCentral.Controls.Agents.Search.AD agentSearchAD = new EFS.RC.SupervisorCentral.Controls.Agents.Search.AD(agentSearchADHost);
			agentSearchAD.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
			agentSearchAD.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
			agentSearchAD.OnUserSelected += ViewSurveyAgentReport_OnUserSelected;

			// set host data
			agentSearchADHost.ResizeMode = System.Windows.ResizeMode.NoResize;
			agentSearchADHost.Title = "Search Agents";
			agentSearchADHost.HostedContent = agentSearchAD;
			agentSearchADHost.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
			agentSearchADHost.Show(null);
		}

		/// ViewSurveyAgentReport_OnUserSelected
		private void ViewSurveyAgentReport_OnUserSelected(EFS.AD.User user)
		{
			// get user
			if (null == user)
			{
				return;
			}

			// get url
			System.String navigateUri =
				EFS.RC.SupervisorCentral.Common.Main.GetReportViewURL(
					"Survey-Agent",
					new System.String[] { "surveyID", "agentGUID" },
					new System.String[] { lastSurveyClikedID.ToString(), EFS.Common.Functions.Guid.Strip(user.ObjectGuid) });

			// start
			System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("iexplore", navigateUri));
		}
		#endregion
	}

}